package SimpleDict;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import RawDict.MulTagString;
import RawDict.TagString;

public class DictData {
	public int soundOff = -1;
	public int soundLen = -1;
	public String content = "";
	
	public DictData(){
		
	}
	
	public DictData(String s){
		content = s;
	}
	
	public boolean FindSound(){
		return soundLen != -1;
	}
	
	public String GetSimpContent(){
		int nxtTagPos = content.indexOf(TagString.preTag, TagString.TagSize);
		if(nxtTagPos != -1){
			return content.substring(TagString.TagSize, nxtTagPos);
		}
		else{
			return content;
		}
	}
	
	public String GetFullContent(){
		return content;
	}
	
	public String GetContent(int filter){
		String rev = "";
		MulTagString mts = MulTagString.Import(content);
		while(mts != null){
			int pos = WordTag.getValue(mts.tag).ordinal();
			if(((0x01 << pos) & filter) != 0){
				rev += mts.toString();
			}
			mts = mts.nxtString;
		}
		return rev;
	}
	
	public void Write(DataOutputStream writer) throws IOException{
		writer.writeInt(soundOff);
		writer.writeInt(soundLen);
		writer.writeUTF(content);
	}

	public void SetSoundInfo(ArrayList<Integer> infos) {
		if(infos.size() > 0){
			assert(infos.size() == 2);
			soundOff = infos.get(0);
			soundLen = infos.get(1);
		}
	}

	public int GetSoundNum() {
		return 1;
	}

	public void Build(DataOutputStream dstDictWriter) throws IOException {
		Write(dstDictWriter);
	}
}
